package com.qf.util;

import java.io.IOException;
import java.util.Properties;

public class MyFactory {
    private Properties properties = new Properties();

    public MyFactory(){}

    public MyFactory(String config) throws IOException, IOException {
        // 加载配置文件
        properties.load(MyFactory.class.getResourceAsStream(config));
    }

    // 获取对象
    public Object getBean(String beanName) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        // 获得类路径
        String classPath = properties.getProperty(beanName);
        if(classPath!=null){
            Class claz = null;
            // 反射：加载类对象
            claz = Class.forName(classPath);
            // 反射：获得对象
            return claz.newInstance();
        }
        return null;
    }

}
